#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QSerialPort>
#include <QSerialPortInfo>
#include <QPushButton>
#include <QTextBrowser>
#include <QTextEdit>
#include <QVBoxLayout>
#include <QLabel>
#include <QComboBox>
#include <QGridLayout>
#include <QMessageBox>
#include <QDebug>
#include <QGroupBox>
#include <QCheckBox>
#include <QPlainTextEdit>

#include "uisendedittext.h"

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private:
    QSerialPort * serialPort;
    QWidget* mainWidget;
    QHBoxLayout* mainLayout;
    QVBoxLayout* leftLayout;
    QVBoxLayout* rightLayout;

    QComboBox* cbbPortName;
    QComboBox* cbbPortBaud;
    QComboBox* cbbPortCheckBits;
    QComboBox* cbbPortDataBits;
    QComboBox* cbbPortStopBits;
    QComboBox* cbbPortFlowCtrl;

    QPushButton* btnPortOnOff;

    //right layout
    QPlainTextEdit* textRecv;
//    QTextEdit * textEdit;
    UiSendEditText * textEdit;

    QPushButton *btnSend;

    int serialPortOnOff;

    void layoutInit();

    //left layout
    void layoutLeftInit();
    QGroupBox* layoutPortConfInit();
    QGroupBox* layoutPortSendConfInit();

    //send line add  line feed
    QCheckBox* cbPortSendConf_add_lf;
    int portSendConf_add_lf;


    //right layout
    void layoutRightInit();

    //
    void portNameScan();
    void portBaudRateItemInit();
    void portDataBitsItemInit();
    void portStopBitsItemInit();
    void portParityItemInit();
    void portFlowCtrlItemInit();

    void portInit();

//protected:
//    bool event(QEvent *event) override;
public slots:
    void sendPushButtonClick();

private slots:
    void openSerialPortPushButtonClicked();
    void serialPortReadyRead();

    void cbPortSendConf_add_lf_state_change(int state);
};
#endif // MAINWINDOW_H
